package inabit.test.main;

import inabit.base.RuleBase;
import inabit.base.WorkingMemory;
import inabit.crisp.inference.ForwardEngineImpl;
import inabit.data.FireableRule;
import inabit.data.Variable;
import inabit.data.expression.ConsequentExpression;
import inabit.data.expression.Expression;
import inabit.data.expression.RelationalExpression;
import inabit.data.expression.arithmetic.NumberExpression;
import inabit.impl.data.ContinuousVariable;

/**@author Rafael Rocha*/
public class Main {
	public static void main(String[] args) throws Exception {
		
		RuleBase rb = new RuleBase();
		WorkingMemory wm = new WorkingMemory();
		
		ForwardEngineImpl f = new ForwardEngineImpl();
		
		wm.addVariable(new ContinuousVariable("temp"));
		wm.addVariable(new ContinuousVariable("speed"));
		wm.addVariable(new ContinuousVariable("motor"));
		
		wm.setVariableValue("temp", "10");
		
		Expression precedent = new RelationalExpression("temp", RelationalExpression.LESS_OR_EQUAL, new NumberExpression(20));
		ConsequentExpression consequent = new RelationalExpression("speed", RelationalExpression.EQUAL, new NumberExpression(50));
		
		Expression precedent2 = new RelationalExpression("speed", RelationalExpression.LESS_OR_EQUAL, new NumberExpression(50));
		ConsequentExpression consequent2 = new RelationalExpression("motor", RelationalExpression.EQUAL, new NumberExpression(80));
		
		
		rb.addRule(new FireableRule("r0", precedent, consequent));
		rb.addRule(new FireableRule("r1", precedent2, consequent2));
		
		f.inference(rb, wm);
		
		for(Variable v : wm.getVariables()) {
			if(v.getValue() == null) {
				System.out.println(v.getID() + " = ?");
			}else {
				System.out.println(v.getID() + " = " + v.getValue());
			}
		}
	}
}
